$(function() {
	    var dataBagId = parent.$(".databag-flag").attr("dataBagId");
	    var returnBtn = parent.$(".databag_return a");
        if(returnBtn.length > 0){
            returnBtn[0].href= parent.$(".databag-flag").attr("data-back");
        }
	    $.ajax({
	        url: "/databag/bag/"+dataBagId+"/path/manifest.json",
	        dataType: "json",
	        success: function(data) {
	            Databag.parseManifest(data);
	            var rep = Databag.Views[0].Representations;
	            for( var i=0 ; i < rep.length ; i++)
	        	{
	        		if( rep[i].MIME == "application/x-shockwave-flash" && rep[i].Attributes.Category == "Preview")
	        		{
	        		    $('#documentViewer').FlexPaperViewer(
	        	                    { config : {
	        	                        SWFFile : "/databag/bag/"+ dataBagId +"/path/"+rep[i].Path,
	        	                        Scale : 0.6,
	        	                        ZoomTransition : 'easeOut',
	        	                        ZoomTime : 0.5,
	        	                        ZoomInterval : 0.2,
	        	                        FitPageOnLoad : true,
	        	                        FitWidthOnLoad : false,
	        	                        FullScreenAsMaxWindow : false,
	        	                        ProgressiveLoading : false,
	        	                        MinZoomSize : 0.2,
	        	                        MaxZoomSize : 5,
	        	                        SearchMatchAll : false,
	        	                        InitViewMode : 'Portrait',
	        	                        RenderingOrder : 'flash,html',
	        	                        StartAtPage : '',

	        	                        ViewModeToolsVisible : true,
	        	                        ZoomToolsVisible : true,
	        	                        NavToolsVisible : true,
	        	                        CursorToolsVisible : true,
	        	                        SearchToolsVisible : true,
	        	                        WMode : 'window',
	        	                        localeChain: 'en_US',
	        	                        jsDirectory : "/databag/js/",
	        	                        cssDirectory : "/databag/css/"
	        	                    }}
	        	            );
	        		}
	        	}
	        }   
	    })
	})
